package com.common.base.utils

import android.graphics.ColorMatrix
import android.graphics.ColorMatrixColorFilter
import android.graphics.Paint
import android.view.View

/**
 *
 * 作者：sosou
 *
 * 版本：1.0
 *
 * 创建日期：2/3/2023
 *
 * 描述：公祭日工具类
 *
 * 修订历史：
 *
 */
class GrayManagerUtils {
    //硬件加速置灰方法
    fun setLayerGrayType(view: View) {
        view.setLayerType(View.LAYER_TYPE_HARDWARE, getMatrix(1))
    }

    //硬件加速置灰方法
    fun setLayerGrayType(type: Int, view: View) {
        view.setLayerType(View.LAYER_TYPE_HARDWARE, getMatrix(type))
    }

    companion object {
        private var mInstance: GrayManagerUtils? = null
        val instance: GrayManagerUtils?
            get() {
                if (mInstance == null) {
                    synchronized(GrayManagerUtils::class.java) {
                        if (mInstance == null) {
                            mInstance = GrayManagerUtils()
                        }
                    }
                }
                return mInstance
            }

        /**
         * @param type 0:正常 1黑白
         * @return
         */
        fun getMatrix(type: Int): Paint {
            val paint = Paint()
            val cm = ColorMatrix()
            when (type) {
                0 -> cm.setSaturation(1f)
                1 -> cm.setSaturation(0f)
                else -> {}
            }
            paint.colorFilter = ColorMatrixColorFilter(cm)
            return paint
        }
    }
}